package com.ssy.lingxi.product.entity.channelCommodity;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.product.entity.commodity.Commodity;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 商品实体类
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/28
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_channel_commodity")
public class ChannelCommodity implements Serializable {
    private static final long serialVersionUID = 7773086978168359546L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="channel_commodity_seq")
    @SequenceGenerator(sequenceName="product_channel_commodity_seq", name="channel_commodity_seq",allocationSize = 1)
    private Long id;

    /**
     * 商品
     */
    @OneToOne(cascade = {CascadeType.PERSIST})
    @JoinColumn(name="commodityId",referencedColumnName = "id")
    private Commodity commodity;

    /**
     * 商品来源：1-上级渠道, 2-渠道自有
     */
    @Column(columnDefinition = "int", nullable = false)
    private Integer source;

    /**
     * 上级渠道商品
     */
    @OneToOne(cascade = {CascadeType.PERSIST})
    @JoinColumn(name="parentChannelCommodityMemberId",referencedColumnName = "id")
    private ChannelCommodityMember parentChannelCommodityMember;

    /**
     * 上级渠道id
     */
    @Column(columnDefinition = "int8")
    private Long parentMemberId;

    /**
     * 上级渠道名称
     */
    @Column(columnDefinition = "varchar(50)")
    private String parentMemberName;

    /**
     * 下级渠道会员角色id
     */
    @Column(columnDefinition = "int8")
    private Long childMemberRoleId;

    /**
     * 下级渠道会员角色名称
     */
    @Column(columnDefinition = "varchar(50)")
    private String childMemberRoleName;

    /**
     * 是否所有下级渠道会员
     */
    @Column(columnDefinition = "boolean")
    private Boolean isAllMember;

    /**
     * 渠道商品对应的下级渠道会员
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "channelCommodity", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    private List<ChannelCommodityMember> memberList;

    /**
     * 渠道商品会员id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberId;

    /**
     * 渠道商品会员名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberName;

    /**
     * 渠道商品会员角色id
     */
    @Column(columnDefinition = "int8")
    private Long memberRoleId;

    /**
     * 渠道商品会员角色名称
     */
    @Column(columnDefinition = "varchar(50)")
    private String memberRoleName;

    /**
     * 渠道商品用户id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long userId;

    /**
     * 渠道商品用户名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String userName;

    /**
     * 渠道商品创建时间
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long createTime = System.currentTimeMillis();
}
